package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.QrtzSimpleTriggers;
import io.mybatis.example.springboot.service.QrtzSimpleTriggersService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * QRTZ_SIMPLE_TRIGGERS - 简单触发器的信息表
 *
 * @author mkj
 */
@RestController
@RequestMapping("qrtzSimpleTriggerses")
public class QrtzSimpleTriggersController {

  @Autowired
  private QrtzSimpleTriggersService qrtzSimpleTriggersService;

  @PostMapping
  public DataResponse<QrtzSimpleTriggersDO> save(@RequestBody QrtzSimpleTriggersDO qrtzSimpleTriggers) {
    return DataResponse.ok(qrtzSimpleTriggersService.save( qrtzSimpleTriggers));
  }

  @GetMapping
  public RowsResponse<QrtzSimpleTriggersDO> findList(@RequestBody QrtzSimpleTriggersDO qrtzSimpleTriggers) {
    return RowsResponse.ok(qrtzSimpleTriggersService.findList( qrtzSimpleTriggers));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<QrtzSimpleTriggersDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(qrtzSimpleTriggersService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<QrtzSimpleTriggersDO> update(@PathVariable("id") Long id, @RequestBody QrtzSimpleTriggersDO qrtzSimpleTriggers) {
    qrtzSimpleTriggers.setId(id);
    return DataResponse.ok(qrtzSimpleTriggersService.update( qrtzSimpleTriggers));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(qrtzSimpleTriggersService.deleteById(id) == 1);
  }

}
